<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <link rel="stylesheet" href="../../css/base.css" />
	<link rel="stylesheet" href="../../css/info-mgt.css" />
	<link rel="stylesheet" href="../../css/WdatePicker.css" />
	<script type="text/javascript" src="../../js/jquery.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript" src="../../js/WdatePicker.js"></script>
	<script type="text/javascript" src="../../js/jquery.pagination.js"></script>
	<title></title>
	</head>

	<body>
	<div class="title"><h2>工作计划申请情况</h2></div>
	<div class="query">
		<div class="query-conditions ue-clear">
	        <div id="searchDept" class="conditions name ue-clear" style="width:20%;">
	            <label>部门名称:</label>
	            <div class="select-wrap">
	                <div class="select-title ue-clear"><span id="dept">请选择</span><i class="icon"></i></div>
	                <ul class="select-list" id="liDept">
	                    <!-- 部门li标签 -->
	                </ul>
	            </div>
	        </div>
	        <div class="conditions name ue-clear" style="width:20%;">
	            <label>计划类型:</label>
	            <div class="select-wrap">
	                <div class="select-title ue-clear"><span id="type">请选择</span><i class="icon"></i></div>
	                <ul class="select-list">
	                    <li>加班</li>
	                    <li>请假</li>
	                </ul>
	            </div>
	        </div>
	        <div class="conditions name ue-clear" style="width:20%;">
	            <label>申请状态:</label>
	            <div class="select-wrap">
	                <div class="select-title ue-clear"><span id="status">请选择</span><i class="icon"></i></div>
	                <ul class="select-list">
	                    <li>未审核</li>
	                    <li>已批准</li>
	                    <li>未通过</li>
	                </ul>
	            </div>
	        </div>
	        <div class="conditions time ue-clear" style="width:19%;">
	            <label>计划时间:</label>
	            <div class="time-select">
	            	<input id="startTime" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" placeholder="开始时间" />
	                <i class="icon"></i>
	            </div>
	            <span class="line">-</span>
	            <div class="time-select">
	            	<input id="endTime" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" placeholder="开始时间" />
	                <i class="icon"></i>
	            </div>
	        </div>
	    </div>
	    <div class="query-btn ue-clear">
	    	<a href="javascript:;" class="confirm">查询</a>
	        <a href="javascript:;" class="clear">清空条件</a> 
	    </div>
	</div>
	<div class="table-box">
		<table>
	    	<thead>
	        	<tr>
	            	<th class="num">申请计划时间</th>
	                <th class="name">申请计划类型</th>
	                <th class="name">所属部门</th>
	                <th class="node">申请人</th>
	                <th class="node">申请详情</th>
	                <th class="time">提交时间</th>
	                <th class="node">处理人</th>
	                <th class="time">处理时间</th>
	                <th class="node">申请状态</th>
	                <th class="operate">操作</th>
	            </tr>
	        </thead>
	        <tbody id="planTbody">
	        	<!-- 工作计划申请情况表格 -->
	        </tbody>
	    </table>
	</div>
	<!-- 分页按钮 ------------------------------------------------->
	<div style="margin:0px auto; width:100%; text-align:center;">
	  	<table id="tableLast" width="80%" align="center" border="0">
	  		<tr align="center">
	  			<td width="75%"></td>
	  			<td><a href="javascript:void(0);" id="headPage">首页</a></td>
	  			<td><a href="javascript:void(0);" id="backPage">上一页</a></td>
	  			<td align="right">当前页面:</td>
	  			<td width="8%" align="left"><input type="text" id="page" value="1" style="width:20%;">
	  				<a href="javascript:void(0);" id="skipPage">跳转</a>&nbsp;&nbsp;
	  				<label id="nowPage">1</label>/<label id="countPage"></label>
	  			</td>
	  			<td><a href="javascript:void(0);" id="nextPage">下一页</a></td>
	  			<td><a href="javascript:void(0);" id="lastPage">末页</a></td>
	  		</tr>
	  	</table>
	  	<br/>
  	</div>
	
	
	</body>
	
	<script type="text/javascript">
	//查询字符串
	var condition="";
	var dept="";
	var status="未审核";
	var other="";
	
	//编辑按钮
	function edit(i){
		$("#aEl"+i).replaceWith("<a onclick='across("+i+");' id='across"+i+"' href='javascript:void(0);'>批准</a>");
		$("#across"+i).after("&nbsp;&nbsp;&nbsp;<a onclick='refuse("+i+");' id='refuse"+i+"' href='javascript:void(0);'>驳回</a>");
		$("#refuse"+i).after("&nbsp;&nbsp;&nbsp;<a onclick='returnA("+i+")' id='returnA"+i+"' href='javascript:void(0);'>返回</a>");
	}
	
	//审核类型变量 审核调用方法
	var type="";
	function exam(i){
		var id=$("#text"+i).val();
		$.ajax({
		 type:"POST",
		 url:"planConditionManager.action?method=update&id="+id,
		 data:"type="+type,
		 success:function(msg){
		 	$("#across"+i).replaceWith("<a>已审核</a>");
		 	$("#refuse"+i).remove();
		 	$("#returnA"+i).remove();
		 	//修改审核行数据
		 	$("#handler"+i).text("李文港");
		 	$("#handlerTime"+i).text(msg);
		 	$("#type"+i).text(type);
		 	
		 }
		});
	}
	//审核通过
	function across(i){
		if(window.confirm("是否批准该项审核?")){
			type="已批准";
			exam(i);
		}
		
	}
	//审核驳回
	function refuse(i){
		if(window.confirm("是否驳回该项审核?")){
			type="未通过";
			exam(i);
		}
	}
	//返回
	function returnA(i){
		$("#across"+i).replaceWith("<a onclick='edit("+i+");' id='aEl"+i+"' href='javascript:void(0);'>审核</a>");
		$("#refuse"+i).remove();
		$("#returnA"+i).remove();
	}
	
	$(function(){
		//异步查询部门信息 加入下拉列表
		$.ajax({
		 type:"POST",
		 url:"planConditionManager.action",
		 data:"method=queryDept",
		 success:function(msg){
		 	var str="";
		 	for(var i=0;i<msg.length;i++){
		 		str+="<li>"+msg[i].deptName+"</li>";
		 	}
		 	$("#liDept").html(str);
		 }
		});
		
		//异步查找工作计划申请情况
		function paging(condition){
			if(isCondition){
				var type=$("#type").text();
				var startTime=$("#startTime").val();
				var endTime=$("#endTime").val();
				if($("#dept").text()!="请选择"){
					dept=$("#dept").text();
				}
				if(type!="请选择"){
					other+="&plan_type="+type;
				}
				if($("#status").text()!="请选择"){
					status=$("#status").text();
				}
				//拼接时间查询字符串
				if(startTime!=""&&endTime!=""){
					other+="&plan_time="+startTime+","+endTime;
				}else if(startTime!=""&&endTime==""){
					other+="&plan_time="+startTime+",8888-08-08";
				}else if(startTime==""&&endTime!=""){
					other+="&plan_time=1111-11-11,"+endTime;
				}
			}
			$.ajax({
			 type:"POST",
			 url:"accLwg*apply_plan.paging",
			 data:condition+"&apply_dept="+dept+other+"&cru_condition="+status,
			 success:function(msg){
			 	other="";
			 	var str="";
			 	for(var i=0;i<msg.data.length;i++){
			 		str+="<tr><td class='num'>"+msg.data[i].planTime+"</td>";
			 		str+="<td class='name'>"+msg.data[i].planType+"</td>";
		            str+="<td class='process'>"+msg.data[i].applyDept+"</td>";
		            str+="<td class='node'>"+msg.data[i].applyName+"</td>";
			 		str+="<td class='time'>"+msg.data[i].planDetail+"</td>";
		            str+="<td class='name'>"+msg.data[i].applyTime+"</td>";
		            str+="<td width='7%' id='handler"+i+"' class='operate'>"+msg.data[i].crcHandler+"</td>";
			 		str+="<td width='10%' id='handlerTime"+i+"' class='time'>"+msg.data[i].crcHandlerTime+"</td>";
		            str+="<td width='7%' id='type"+i+"' class='name'>"+msg.data[i].cruCondition+"</td>";
		            str+="<input id='text"+i+"' type='hidden' value='"+msg.data[i].applyId+"' />";
		            str+="<td width='7%' class='operate'>";
		            //如果不是人力资源和总经理 则不能操作
		            if("${login_User.userDeptId }"!="2"&&"${login_User.userDeptId }"!="4"){
		            	str+="<a>无</a>"
		            }else{
			            if(msg.data[i].cruCondition=="未审核"){
			            	str+="<a onclick='edit("+i+");' id='aEl"+i+"' href='javascript:void(0);'>审核</a>";
			            }else{
			            	str+="<a>已审核</a>";
			            }
			        }
		            str+="</td></tr>";
			 	}
			 	if(i<15){
			 		for(;i<15;i++){
			 			str+="<tr><td class='name'> - </td></tr>";
			 		}
			 	}
			 	$("#planTbody").html(str);
			 	//向上取整总页数
				$("#countPage").text(Math.ceil(msg.rowNum/15));
			 }
			});
		}
		//异步查询部门信息
		var id="${login_User.userDeptId }";
		$.ajax({
		 type:"POST",
		 url:"planConditionManager.action?method=queryDeptById",
		 data:"id="+id,
		 success:function(msg){
		 	if(id=="2"||id=="4"){
		 		dept="";
		 	}else{
		 		dept=msg;
		 	}
		 	//调用分页
			condition="nowPage=0&turnType=next";
			paging(condition);
		 }
		});
		
		//首页
		$("#headPage").click(function(){
			if($("#nowPage").text()==1){
			}else{
				data="nowPage=0&turnType=next";
				paging(data);
				$("#nowPage").text(1);
				$("#page").val(1);
			}
		});
		//末页
		$("#lastPage").click(function(){
			if($("#nowPage").text()==$("#countPage").text()){
			}else{
				data="nowPage="+(parseInt($("#countPage").text())-1)+"&turnType=next";
				paging(data);
				$("#nowPage").text($("#countPage").text());
				$("#page").val($("#nowPage").text());
			}
		});
		//上一页
		$("#backPage").click(function(){
			if($("#nowPage").text()==1){
			}else{
				data="nowPage="+$("#nowPage").text()+"&turnType=back";
				paging(data);
				$("#nowPage").text(parseInt($("#nowPage").text())-1);
				$("#page").val($("#nowPage").text());
			}
		});
		//下一页
		$("#nextPage").click(function(){
			if($("#nowPage").text()==$("#countPage").text()){
			}else{
				data="nowPage="+$("#nowPage").text()+"&turnType=next";
				paging(data);
				$("#nowPage").text(parseInt($("#nowPage").text())+1);
				$("#page").val($("#nowPage").text());
			}
		});
		//跳转页面
		$("#skipPage").click(function(){
			if($("#page").val()>$("#countPage").text()||$("#page").val()<1||
			$("#page").val()==$("#nowPage").text()){
			}else{
				data="nowPage="+(parseInt($("#page").val())-1)+"&turnType=next";
				paging(data);
				$("#nowPage").text($("#page").val());
			}
		});
		
		//清空按钮
		$(".clear").click(function(){
			$("#status").text("请选择");
			$("#dept").text("请选择");
			$("#type").text("请选择");
			$("#startTime").val("");
			$("#endTime").val("");
			isCondition=false;
			dept="部";
			status="未审核";
			
		});
		var isCondition=false;//是否使用查询条件
		//查询按钮
		$(".confirm").click(function(){
			//调用分页
			isCondition=true;
			condition="nowPage=0&turnType=next";
			paging(condition);
		});
		
	});
	
	
	
	$(function(){
		$(".select-title").on("click",function(){
			$(".select-list").hide();
			$(this).siblings($(".select-list")).show();
			return false;
		});
		$(".select-list").on("click","li",function(){
			var txt = $(this).text();
			$(this).parent($(".select-list")).siblings($(".select-title")).find("span").text(txt);
		});
	});
	
	//如果部门不是人力资源或总经理 则隐藏部门搜索条件  
	if("${login_User.userDeptId }"!="2"&&"${login_User.userDeptId }"!="4"){
		$("#searchDept").hide();
	}
	
	
	//改变分页按钮字体大小
	$("#tableLast tr td").css("font-size","15px");
	$("#tableLast tr td").css("background","url(../../images/righttitlebig.png)");
	
	$("tbody").find("tr:odd").css("backgroundColor","#eff6fa");
	
	showRemind('input[type=text], textarea','placeholder');
</script>
</html>
